/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.staff;

import entities.StaffDetail;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 *
 * @author VietLH
 */
public class StaffViewAllTblMdl implements TableModel {

    private ArrayList<StaffDetail> staffList;
    private String[] header = {"Staff Name", "Address", "Date of Birth", "Gender", "Phone"};

    public StaffViewAllTblMdl(ArrayList<StaffDetail> staffList) {
        this.staffList = new ArrayList<StaffDetail>();
        this.staffList = staffList;
    }

    public void setHeader(String[] header) {
        this.header = header;
    }

    @Override
    public int getRowCount() {
//        throw new UnsupportedOperationException("Not supported yet.");
        return staffList.size();
    }

    @Override
    public int getColumnCount() {
//        throw new UnsupportedOperationException("Not supported yet.");
        return header.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
//        throw new UnsupportedOperationException("Not supported yet.");
        return header[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
//        throw new UnsupportedOperationException("Not supported yet.");
        if (columnIndex == 2) {
            return Date.class;
        }
        return String.class;
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
//        throw new UnsupportedOperationException("Not supported yet.");
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
//        throw new UnsupportedOperationException("Not supported yet.");
        if(staffList.size()>0&&staffList!=null){
            if(columnIndex==0){
                return staffList.get(rowIndex);
            }
            else if(columnIndex==1){
                return staffList.get(rowIndex).getStaffAddress();
            }
            else if(columnIndex==2){
                return staffList.get(rowIndex).getStaffDOB();
            }
            else if(columnIndex==3){
                if(staffList.get(rowIndex).isStaffGender()){
                    return "Male";
                }
                else{
                    return "Female";
                }
            }
            else if(columnIndex==4){
                return staffList.get(rowIndex).getStaffPhone();
            }
            else{
                return "-----";
            }
        }else{
            return "-----";
        }
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
//        throw new UnsupportedOperationException("Not supported yet.");
    }
}
